/**
 * Created by CXL on 2016/6/28.
 */
package com.invexer.baosteel.app.model {
import com.invexer.common.puremvc.patterns.proxy.InvexerSimpleModelBase;
import com.invexer.service.baosteel.IBaoSteelService;

import flash.utils.getDefinitionByName;
import flash.utils.setTimeout;

public class BaosteelConfigModelBase extends InvexerSimpleModelBase{
    protected var _config:Object;
    protected var _webService:IBaoSteelService;
    protected var _httpService:IBaoSteelService;

    public function BaosteelConfigModelBase(key:String) {
        super(key);
    }

    public function set config(value:Object):void{
        if(_config == value) return;
        _config = value;
    }

    protected function get productionMode():String{
        return _config.productionMode;
    }

    public function get refreshInternal():int{
        return _config.refreshInternal[productionMode];
    }

    public function get webService():IBaoSteelService{
        if(!_webService){
            var serviceCls:Class = getDefinitionByName(_config.webServiceClass) as Class;

            _webService = new serviceCls();
            _webService.productionMode = productionMode;
            _webService.config = _config.webService;
        }
        return _webService;
    }

    public function get httpService():IBaoSteelService{
        if(!_httpService){
            var serviceCls:Class = getDefinitionByName(_config.httpServiceClass) as Class;

            _httpService = new serviceCls();
            _httpService.productionMode = productionMode;
            _httpService.config = _config.httpService;
        }

        return _httpService;

    }
}
}
